package com.mall.tag;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.mall.ibatis.bean.IFormat;

@SuppressWarnings("serial")
public class KeyValueTag extends TagSupport{
	
	private List<IFormat> list;
	private String value;
	
	public int doStartTag() throws JspException
	{
		try
		{
			JspWriter out = pageContext.getOut();
			
			//  value = "FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX";
			StringBuffer buffer = new StringBuffer();
			int index = 1;
			buffer.append(value + " = '");
			for(IFormat i:list)
			{
				buffer.append(i.toKeyValue());
				if(index < list.size())
				{
					buffer.append(";");
				}
				index++;
			}
			buffer.append("';\n");
			
			out.print(buffer.toString());
			out.flush();
		}
		catch (Exception e)
		{
			// TODO: handle exception
			throw new JspTagException(e.getMessage());
		}
		
		
		return SKIP_BODY;
	}

	public List<IFormat> getList() {
		return list;
	}

	public void setList(List<IFormat> list) {
		this.list = list;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
}
